function   parameters_matrix = smolayak_parameter_grid_generation( parameters_baseline,  accuracy_level, deviation_percentage, shutoff_positions  )
% Usage: parameters_matrix_output = smolayak_parameter_grid_generation(
% parameters_baseline,  accuracy_level)
% 
% parameters_baseline is a row vector that contains the parameter values in the baseline. "accuracy_level" controls the how fine the grid is.  A
% typical choice is 2 or 3.   deviation_percentage  controls the range of the grid in each dimension, relative to the baseline.
% deviation_percentage=0.25 means that at each direction parameters deviate 25%

if(nargin<4)
    shutoff_positions = [];
end

%% ----------------------------------------------------------------
%     Generate a Smolayak Grid and then Export that to the calibration.xlsx
% ------------------------------------------------------------------------
d     =   size(parameters_baseline, 2) - length(shutoff_positions) ;                  % Number of dimensions
                            
vector_mus_dimensions =  accuracy_level* ones( d, 1 );    % Note: we can have difference accuracy at different dimensions. For example, we can put a matrix [3, 5, 4, 2, ...] that specifies different levels of approximation at different dimensions. 
                            % Introduce the level of approximation in every  lambda_H=par_default.lambda_H;
                            % dimension from 1 to 10; see Section 4 of 
                            % JMMV (2014)

mu_max  = max(vector_mus_dimensions);
                            % Compute the maximum level of approximation
                            % across all dimensions

Smolyak_elem_iso = Smolyak_Elem_Isotrop(d,mu_max);
    % Construct the matrix of indices of multidimesional Smolyak elements 
    % (grid points and polynomial basis functions) that satisfy the usual 
    % isotropic Smolyak rule for the approximation level equal to "mu_max"
    
Smol_elem_ani = Smolyak_Elem_Anisotrop(Smolyak_elem_iso,vector_mus_dimensions);
    % Select from the matrix of isotropic indices "Smol elem_iso" a subset of 
    % indices that correspond to the given anisotropic "vector_mus_dimensions"
   
Smol_grid_ani = Smolyak_Grid(d,mu_max,Smol_elem_ani);   % A grid that has scale from -1 to 1. 
    % Construct the Smolyak grid for the given subindices of anisotropic  
    % Smolyak elements "Smol_elem_ani" 

% Construct the deviations as maximum at deviation_percentage.
multiplier_matrix = Smol_grid_ani  * deviation_percentage;  

% Adjust for the shutoff positions
if( ~isempty(shutoff_positions) )  % if there are positions of the parameters that do not need grid search
    multiplier_matrix_raw = multiplier_matrix;
    multiplier_matrix = zeros( size(Smol_grid_ani,1),  length(parameters_baseline)  );
    counter=1;
    for( j = 1:length(parameters_baseline) )   
        if( ismember( j, shutoff_positions ) )
            multiplier_matrix(:,j) = 0;
        else
            multiplier_matrix(:,j) = multiplier_matrix_raw(:,counter);
            counter = counter+1;
        end
    end
end

parameters_matrix = (1 + multiplier_matrix) .* parameters_baseline;



